package cn.nohan.funplay.module.member.mongo.controller;

/**
 * @author caozhipeng
 * @date 2025/7/11
 */

import cn.nohan.funplay.module.member.mongo.annotation.ResponseResult;
import cn.nohan.funplay.module.member.mongo.annotation.SkipResponseWrapper;
import cn.nohan.funplay.module.member.mongo.entity.MongoDynamicEntity;
import cn.nohan.funplay.module.member.mongo.entity.MongoGroupResultDTO;
import cn.nohan.funplay.module.member.mongo.entity.MongoUserTrajectoryEntity;
import cn.nohan.funplay.module.member.mongo.service.DynamicService;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.GeoResults;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@RequestMapping("/info")
@RestController
@ResponseResult
public class DynamicController {

    @Autowired
    private  DynamicService dynamicService;

    @RequestMapping("/getById")
    public MongoDynamicEntity getById(@RequestParam("id") String id) {
        return dynamicService.getById(id);
    }

    @RequestMapping("/getOneUser")
    public Document getOneUser() {
        return dynamicService.getOneUser(31L);
    }

    @RequestMapping("/test")
    public List<Document> getTest() {
        return dynamicService.test();
    }

    @RequestMapping("/getOneUser2")
    public MongoUserTrajectoryEntity getOneUser2() {
        return dynamicService.getOneUser2(31L);
    }

    @RequestMapping("/save")
    public void save(@RequestParam("userId") Long userId,
                     @RequestParam("longitude") Double longitude,
                     @RequestParam("latitude") Double latitude){
        dynamicService.save(userId,longitude,latitude);
    }
    @RequestMapping("/getNearUser")
    public GeoResults<Document> getNearUser(){
        return dynamicService.getNearUser();
    }

    @RequestMapping("/getById2")
    public Document getById2(@RequestParam("id") String id) {
        return dynamicService.getById2(id);
    }

    @GetMapping("/getName")
    public String getName(){
        return "Hello";
    }

    @GetMapping("/getName4")
    public void getName4(){
        System.out.println("hello");
    }

    @GetMapping("/getName2")
    public List<String> getName2(){
        List<String> list = new ArrayList<>();
        list.add("AAAA");
        list.add("VVVV");
        list.add("DDD");
        list.add("SSSS");
        return list;
    }

    @GetMapping("/getName3")
    @SkipResponseWrapper
    public List<String> getName3(){
        List<String> list = new ArrayList<>();
        list.add("AAAA");
        list.add("VVVV");
        list.add("DDD");
        list.add("SSSS");
        return list;
    }



    @RequestMapping("/getList")
    public List<MongoDynamicEntity> getList() {
        return dynamicService.getList();
    }

    @RequestMapping("/getGroupCount")
    public void getGroupCount() {
         dynamicService.getGroupCount();
    }

    @RequestMapping("/getCount")
    public List<MongoGroupResultDTO> getCount() {
       return dynamicService.getCount();
    }

    @RequestMapping("/getByUserIds")
    public List<Long> getByUserIds() {
        return dynamicService.getSupperUserList();
    }
    @RequestMapping("/getByUserIds2")
    public List<Document> getByUserIds2() {
        return dynamicService.getSupperUserList2();
    }

    @RequestMapping("/getLeftJoin")
    public List<Long> getLeftJoin() {
        return dynamicService.getLeftJoin(Arrays.asList(50L,45L,30L,100L),7L);
    }

    @RequestMapping("/deleteById")
    public Boolean deleteById( @RequestParam("id") String id){
        return dynamicService.deleteById(id);
    }

    @RequestMapping("/initDynamicDeleted")
    public String initDynamicDeleted(){
         dynamicService.initDynamicDeleted();
         return "success";
    }
}
